package com.tian.controller;

import com.tian.dto.PayNotifyTestReqDto;
import com.tian.enums.PaymentChannelEnum;
import com.tian.service.NotifyPayService;
import com.tian.service.PayBaseService;
import com.tian.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * {@code @description:} TODO
 *
 * @author tianwc 公众号：Java后端技术全栈
 * 在线刷题 1200+java面试题和1000+篇技术文章：<a href="https://woaijava.cc/">博客地址</a>
 * {@code @date:} 2025-01-20 9:54
 * {@code @version:} 1.0
 */
@Slf4j
@RestController
@RequestMapping("/paymment/notify")
public class PayNotifyController {

    @Resource
    private NotifyPayService notifyPayService;
    @PostMapping("/alipay")
    public ResponseEntity<String>  payNotifyAliPay(HttpServletRequest request, @RequestBody PayNotifyTestReqDto payNotifyTestReqDto) {
        try {
            return notifyPayService.payNotify(request, payNotifyTestReqDto, PaymentChannelEnum.ALIPAY.getChannel());
        } catch (Exception e) {
            log.error("支付宝支付回调通知异常", e);
            return new ResponseEntity<>("failed", HttpStatus.EXPECTATION_FAILED);
        }
    }

    @PostMapping("/wxpay")
    public ResponseEntity<String> payNotifyWxPay(HttpServletRequest request, @RequestBody PayNotifyTestReqDto payNotifyTestReqDto) {
        try {
            return notifyPayService.payNotify(request, payNotifyTestReqDto, PaymentChannelEnum.WECHAT.getChannel());
        } catch (Exception e) {
            log.error("微信支付回调通知异常", e);
            return new ResponseEntity<>("failed", HttpStatus.EXPECTATION_FAILED);
        }
    }
}
